package kr.hkit.powerjava.chapter24;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

//620페이지
public class CopyFileReader {
	public static void main(String[] args) {

		FileReader fr = null;
		FileWriter fw = null;
		BufferedReader br = null;
		BufferedWriter bw = null;
		PrintWriter pw = null;

		try {
			br = new BufferedReader(new FileReader("input.txt"));
			pw = new PrintWriter (new FileWriter("output2.txt"));
			String line;
			while ((line = br.readLine()) != null){ //readLine은 파일끝에가면 null을 돌려줌
//				bw.write(line); //한줄 읽기!. 
//				bw.write(line+"\n"); //한줄읽기. + 줄 바꿈.
				pw.println(line); //ln이라서 \n안써도되. printWriter
			}
/*
			int c;
			while ((c = fr.read()) != -1) {
				System.out.format("%s", (char) c);
				fw.write(c);
			}*/
		} catch (FileNotFoundException e) {
			System.err.format("%s%n", "파일이 존재하지 않음");
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (br != null) {
				try {br.close();} catch (Exception e) {}
			}
			if (pw != null) {
				try {pw.close();} catch (Exception e) {}
			}
		}
	}
}
